﻿using System;
using DebIt.ViewModel;
using Microsoft.Phone.Controls;

namespace DebIt.View
{
    public partial class ClientEdit : PhoneApplicationPage
    {
        public ClientEdit()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);
            var id = "";
            NavigationContext.QueryString.TryGetValue("id", out id);
            id =  id == "" ? "0" : id;
            DataContext = new ClientEditViewModel(Convert.ToInt32(id));
        }

        protected override void OnNavigatedFrom(System.Windows.Navigation.NavigationEventArgs e)
        {
            ((ClientEditViewModel)DataContext).Save();
        }

        private void BindableApplicationBarIconButtonClick(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }
    }
}